// AskTSAPI.cpp : Implementation of CAskTSAPIApp and DLL registration.

#include "stdafx.h"
#include "AskTSAPI.h"
#include <winsock2.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


CAskTSAPIApp NEAR theApp;

const GUID CDECL BASED_CODE _tlid =
		{ 0xa1ac620e, 0x5723, 0x46eb, { 0x96, 0xe3, 0x96, 0xa7, 0x48, 0xb1, 0xc2, 0x9e } };
const WORD _wVerMajor = 1;
const WORD _wVerMinor = 0;


////////////////////////////////////////////////////////////////////////////
// CAskTSAPIApp::InitInstance - DLL initialization

BOOL CAskTSAPIApp::InitInstance()
{
	BOOL bInit = COleControlModule::InitInstance();

	if (bInit)
	{
		DWORD ret=0;
		CString strErr;
		DWORD i=0;
		WSADATA wsaData;
		if ((ret = WSAStartup(0x0202, &wsaData)) != 0)
		{
			strErr.Format("WSAStartup failed with error:%d", ret);
			return FALSE;
		}
	}

	return bInit;
}


////////////////////////////////////////////////////////////////////////////
// CAskTSAPIApp::ExitInstance - DLL termination

int CAskTSAPIApp::ExitInstance()
{
	// TODO: Add your own module termination code here.

	WSACleanup( );
	return COleControlModule::ExitInstance();
}


/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry

STDAPI DllRegisterServer(void)
{
	AFX_MANAGE_STATE(_afxModuleAddrThis);

	if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
		return ResultFromScode(SELFREG_E_TYPELIB);

	if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
		return ResultFromScode(SELFREG_E_CLASS);

	return NOERROR;
}


/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry

STDAPI DllUnregisterServer(void)
{
	AFX_MANAGE_STATE(_afxModuleAddrThis);

	if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
		return ResultFromScode(SELFREG_E_TYPELIB);

	if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
		return ResultFromScode(SELFREG_E_CLASS);

	return NOERROR;
}
